import { createRouter, createWebHashHistory } from "vue-router"
import baseRoutes from "./base.route"
import moduleRoutes from "./modules"

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: "/",
      name: "Home",
      component: () => import("@/pages/HomePage.vue"),
      children: [
        ...moduleRoutes,
        {
          path: "404",
          name: "PageNotFound",
          component: () => import("@/pages/other/404.vue"),
        },
      ],
    },
    {
      path: "/login",
      name: "Login",
      component: () => import("@/pages/LoginPage.vue"),
    },
  ],
})

router.beforeEach((to, from, next) => {
  if (to.matched && to.matched.length > 0) {
    next()
  } else {
    next({
      path: "/404",
    })
  }
})

export default router
